﻿using Newtonsoft.Json;
using Service.Framework.Packet;

namespace Service.Framework
{
    /// <summary>
    /// 逻辑错误异常
    /// </summary>
    [Serializable]
    public class LogicErrorException : Exception, IKnownException
    {
        /// <summary>
        /// 返回包的状态码
        /// </summary>
        private StatusCode _statusCode;
        /// <summary>
        /// 返回包的消息
        /// </summary>
        private String _message { get; set; }

        /// <summary>
        /// 返回包的消息体内容，Json序列化
        /// </summary>
        private Object _data { get; set; }

        public LogicErrorException()
        {
            _statusCode = StatusCode.KnowException;
            _data = null;
            _message = "";
        }

        public LogicErrorException(String message, StatusCode statusCode = StatusCode.KnowException, Object data = null) : base(message)
        {
            _message = message;
            _statusCode = statusCode;
            _data = data;
        }

        public LogicErrorException(String message, Exception innerException, StatusCode statusCode = StatusCode.KnowException, Object data = null) : base(message, innerException)
        {
            _message = message;
            _statusCode = statusCode;
            _data = data;
        }


        public StatusCode StatusCode => _statusCode;

        public String Mesaage => _message;

        public String Content => JsonConvert.SerializeObject(_data);
    }
}
